#include <bits/stdc++.h>
using namespace std;

string tobit(char c) {
    string s;
    for (int i = 16; i >= 1; i /= 2) {
        if (i <= c) {
            s += '1';
            c -= i;
        } else
            s += '0';
    }
    //cout << s << endl;
    return s;
}

int main() {
    int dir[4][2] = {{0,  1},
                     {1,  0},
                     {0,  -1},
                     {-1, 0}};
    int n, m;
    char *c = new char;
    string s, s1;
    cin >> n >> m;
    cin.get(*c);
    delete c;
    getline(cin, s);

    vector <vector<int>> arr(n + 5, vector<int>(m + 5, -65535));
    for (char i: s) {
        char a;
        if (i == ' ')
            s1 += "00000";
        else {
            a = i - 'A' + 1;
            s1 += tobit(char(a));
        }
    }
    //cout<<s1<<endl;
    int x = 1, y = 1, fx = 0, step = 0;
    while (step < n * m) {
        if (step >= s1.size())
            arr[x][y] = 0;
        else
            arr[x][y] = s1[step] - '0';
        int dx = x + dir[fx][0];
        int dy = y + dir[fx][1];
        if (dx < 1 or dx > n or dy < 1 or dy > m or arr[dx][dy] != -65535)
            (fx += 1) %= 4;
        x += dir[fx][0];
        y += dir[fx][1];
        ++step;
    }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            cout << arr[i][j];
    return 0;
}